<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>加载3dtileset</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-template-columns: 60px 1fr;
            align-items: center;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <h3>偏移值offset</h3>
        <div class="box">
            <label for="">偏移X：</label><input id="offsetx" type="number" value="0" onchange="changeOffsetX()">
            <label for="">偏移Y：</label><input id="offsety" type="number" value="0" onchange="changeOffsetY()">
            <label for="">偏移Z：</label><input id="offsetz" type="number" value="0" onchange="changeOffsetZ()">
        </div>
    </div>
    <script>

        /** -----------------------------------------地球创建----------------------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            "domid": document.getElementById("app")
        })
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                viewer.flyIn([108.96610365677321, 34.206992091389814, 1040.7418042287602], [335.98922025235976, -25.906877001440748, 0.00022993478992045343], 3)
            }
        })
        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });


        /**-----------------------------根据类（Class）创建一个ES3DTileset对象-------------------------------**/

        // Vue中引入方式：import { ES3DTileset } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
        const { ES3DTileset } = XE2['esobjs-xe2-plugin-main']
        const sceneObject = objm.createSceneObject(ES3DTileset)
        sceneObject.url = "https://www.pipeser.com/cesiumlab/G7qC5vBk/tileset.json"
        sceneObject.editing = true

        /**-----------------------------设置3dtileset偏移值-------------------------------**/

        sceneObject.offsetChanged.don((val) => {
            if (Array.isArray(val) && val.length == 3) {
                document.getElementById("offsetx").value = val[0]
                document.getElementById("offsety").value = val[1]
                document.getElementById("offsetz").value = val[2]
            }
        })

        // 设置偏移值X
        function changeOffsetX() {
            let offset = sceneObject.offset ? JSON.parse(JSON.stringify(sceneObject.offset)) : [0, 0, 0]
            offset[0] = Number(document.getElementById("offsetx").value)
            // 整体设置偏移值
            sceneObject.offset = offset
        }

        // 设置偏移值Y
        function changeOffsetY() {
            let offset = sceneObject.offset ? JSON.parse(JSON.stringify(sceneObject.offset)) : [0, 0, 0]
            offset[1] = Number(document.getElementById("offsety").value)
            // 整体设置偏移值
            sceneObject.offset = offset
        }

        // 设置偏移值Z
        function changeOffsetZ() {
            let offset = sceneObject.offset ? JSON.parse(JSON.stringify(sceneObject.offset)) : [0, 0, 0]
            offset[2] = Number(document.getElementById("offsetz").value)
            // 整体设置偏移值
            sceneObject.offset = offset
        }


    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>